<?php

namespace app\meizhuangapi\controller;

use app\meizhuangapi\model\User as UserModel;
use app\api\controller\Controller as ControllerCon;
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Max-Age: 1728000');
/**
 * API控制器基类
 * Class BaseController
 * @package app\store\controller
 */
class Controller extends ControllerCon
{
    /**
     * 获取当前用户信息
     */
    protected function getUser($is_force = true){
        if (!$token = $this->request->param('token')) {
            $is_force && $this->throwError('缺少必要的参数：token', -1);
            return false;
        }
        if (!$user = UserModel::getUser($token)) {
            $is_force && $this->throwError('没有找到用户信息', -1);
            return false;
        }
        if(!empty($user['username'])){
            $user['nickName']=$user['username'];
        }
        return $user;
    }
}
